import  numpy as np
from map_state_main import *
"""
generate the path from corrdinate of car to mobile
[0,
1,2,
3]
output:[2,3,4,1,1,2...]
"""
def find_path(map_list,curr_idx,map_size,dst_idx):
	start=[]
	dst=[]
	for i in range(len(map_list)):
		if map_list[i] == -1 or map_list[i] == 0:
			start.append(map_list[i])
		else:
			if i==curr_idx:
				start.append(-2)
			else:
				start.append(1)
	for i in range(len(map_list)):
		if map_list[i] == -1 or map_list[i] == 0:
			dst.append(map_list[i])
		else:
			if i==dst_idx:
				dst.append(-2)
			else:
				dst.append(1)


	# print(dst)
	# print(start)
	path_list=map_state_main(start,dst,map_size)
	return path_list


def find_path_main(	curr_idx = 1，dst_idx= 10):
	f=open('map.txt','r')
	file=f.read()
	file=file.split('.]')
	final = []
	for tmp in file:
		tmp=tmp.replace('[','')
		tmp=tmp.replace(']','')
		tmp=tmp.replace('\n','')
		tmp=tmp.replace(' ','')
		tmp=tmp.split('.')
		if tmp != ['']:
			final.append(tmp)


	Arr=[]
	for tmp in final:
		tmp_list=[]
		for i in tmp:
			tmp_list.append(int(i))
		Arr.append(tmp_list)
	Arr=np.array(Arr)
	# print(Arr)
	map_size=Arr.shape
	Arr=Arr.reshape(1,map_size[0]*map_size[1])
	
	list1 = Arr.tolist()
	# print(list1[0])
	result=find_path(list1[0],curr_idx,map_size,dst_idx)

# 若其他函数调用本函数，请删除以下代码
# curr_idx利用get_curr_position获得
# dst_idx是主人的位置，获得方法你自己定
curr_idx = 1
# curr_idx=get_curr_position()
dst_idx= 10
find_path_main(curr_idx,dst_idx)